<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="reset">重新开始一局游戏</button><br/>
    请输入要猜的数字：<input type="text" id ="guessNum">
    <button id="userGuess">猜</button><br/>
    已经猜的次数：<span id="count"></span><br/>
    结果：<span id="result"></span>

    <script src="jquery-3.7.1.min.js"></script></body>
    <script>
        var number = Math.floor(Math.random() * 100) + 1;//要猜的数字
        console.log("number：" + number);
        var count = 0;
        //点击猜，看看猜的数字对不对
        $(document).ready(function() {
            $("#userGuess").click(function() {
                count++;
                $("#count").text(count);
                var guessNum = $("#guessNum").val();
                if(guessNum > number) {
                    $("#result").text("猜大了");
                    $("#result").css("color", "red");
                } else if(guessNum < number) {
                    $("#result").text("猜小了");
                    $("#result").css("color", "red");
                } else {
                    $("#result").text("猜对了");
                    $("#result").css("color", "green");
                }
            });
        });

        //点击重开游戏
        $(document).ready(function() {
            $("#reset").click(function() {
                number = Math.floor(Math.random() * 100) + 1;
                console.log("要猜的数字：" + number);
                count = 0;
                $("#count").text("");
                $("#result").text("");
                $("#result").css("color", "");
                $("#guessNum").val("");
            });
        });
    </script>
</body>
</html>